{% extends 'indexTemplate.html' %}
{% load staticfiles %}

{% block title %}授课机构 - 慕学在线网{% endblock %}

{% block customBread %}
<section>
    <div class="wp">
        <ul  class="crumbs">
            <li>
                <a href="{% url 'index' %}">首页</a>>
            </li>
            <li>机构</li>
        </ul>
    </div>
</section>
{% endblock %}

{% block content %}
<section>
<div class="wp butler_list_box list">
	<div class='left'>
		<div class="listoptions">
			<ul>
				<li>
					<h2>机构类别</h2>
					<div class="cont">
                        <a href="?cityId={{ cityId }}">
                            <span class="{% ifequal  category '' %}active2{% endifequal %}">全部</span>
                        </a>
                        <a href="?category=px&cityId={{ cityId }}">
                            <span class="{% ifequal  category 'px' %}active2{% endifequal %}">培训机构</span>
                        </a>
                        <a href="?category=gx&cityId={{ cityId }}">
                            <span class="{% ifequal  category 'gx' %}active2{% endifequal %}">高校</span>
                        </a>
					</div>
				</li>
				<li>
					<h2>所在地区</h2>
					<div class="cont">
                        <a href="?category={{ category }}">
                            <span class="{% ifequal  cityId '' %}active2{% endifequal %}">全部</span>
                        </a>
                        {% for city in citys%}
                        <a href="?cityId={{ city.id }}&category={{ category }}">
                            <span class="{% ifequal  cityId city.id|stringformat:'i' %}active2{% endifequal %}">{{ city.name }}</span>
                        </a>
                        {% endfor %}
					</div>
                    {% if citys|length > 8 %}
                    <div class="more">更多</div>
                    {% endif %}
				</li>
			</ul>
		</div>
		<div class="all">共<span class="key">{{ pageObj.object_list|length }}</span>家</div>

		<div class="butler_list company list">
		    <div class="layout">
                <div class="head">
                    <ul class="tab_header">
                        <li class="{% ifequal sort '' %}active{% endifequal %}">
                            <a href="?category={{ category }}&cityId={{ cityId }}">全部</a>
                        </li>
                        <li class="{% ifequal sort 'students' %}active{% endifequal %}">
                            <a href="?sort=students&category={{ category }}&cityId={{ cityId }}">学习人数 &#8595;</a>
                        </li>
                        <li class="{% ifequal sort 'courses' %}active{% endifequal %}">
                            <a href="?sort=courses&category={{ category }}&cityId={{ cityId }}">课程数 &#8595;</a>
                        </li>
                    </ul>
                </div>
            </div>
            {% for obj in pageObj.object_list%}
            <dl class="des difdes">
                <dt>
                    <a href="{% url 'orgs:orgHome' obj.id %}">
                        <img width="200" height="120" class="scrollLoading" data-url="{{ MEDIA_URL }}{{ obj.image }}"/>
                    </a>
                </dt>
                <dd>
                    <div class="clearfix">
                         <a href="{% url 'orgs:orgHome' obj.id %}">
                             <h1>{{ obj.name }}</h1>
                             <div class="pic fl">
                                 <img src="{% static '/images/authentication.png' %}"/>
                                 <img src="{% static '/images/gold.png' %}"/>
                             </div>
                         </a>
                    </div>
                    <ul class="cont">
                        <li class="first">
                            <p class="pic9">课程数：<span>{{ obj.courses }}</span></p>
                            <p class="c7">学习人数：<span>{{ obj.students }}</span></p>
                        </li>
                        <li class="c8" style="padding-left:18px;">{{ obj.address }}</li>
{#                        <li class="pic10" style="padding-left:18px;">经典课程：#}
{#                            <a href="/diary/19/">c语言基础入门</a>#}
{#                        </li>#}
                    </ul>
                </dd>
                <div class="buy start_groupbuy jsShowPerfect2" data-id="22"><br/>联系<br/>服务</div>
            </dl>
            {% endfor %}
        </div>

        <div class="pageturn">
            <ul class="pagelist">
            {% if pageObj.has_previous %}
                <li class="long"><a href="?{{ pageObj.previous_page_number.querystring }}">上一页</a></li>
            {% endif %}

            {% if pageObj.object_list|length > 0 %}
                {% for page in pageObj.pages %}
                    {% if page %}
                        {% ifequal page pageObj.number %}
                        <li class="active">
                            <a class="page" href="?{{ page.querystring }}">{{ page }}</a>
                        </li>
                        {% else %}
                        <li>
                            <a class="page" href="?{{ page.querystring }}">{{ page }}</a>
                        </li>
                        {% endifequal %}
                    {% else %}
                        <li><a href="#" class="none">...</a></li>
                    {% endif %}
                {% endfor %}
            {% endif %}

            {% if pageObj.has_next %}
                <li class="long"><a href="?{{ pageObj.next_page_number.querystring }}">下一页</a></li>
            {% endif %}
            </ul>
        </div>
    </div>

	<div class="right companyright">
        <div class="head">我要学习</div>
        <form class="rightform" id="jsStayForm">
        {% csrf_token %}
            <div>
                <img src="/static/images/rightform1.png"/>
                <input type="text" name="name" id="name" placeholder="名字" maxlength="25" />
            </div>
            <div>
                <img src="/static/images/rightform2.png"/>
                <input type="text" name="mobile" id="mobile" placeholder="联系电话"/>
            </div>
            <div>
                <img src="/static/images/rightform3.png"/>
                <input type="text" name="courseName" id="courseName" placeholder="课程名" maxlength="50" />
            </div>
            <p class="error company-tips" id="jsCompanyTips"></p>
            <input class="btn" type="text" id="jsStayBtn" value="立即咨询" />
        </form>
    </div>

    <div class="right companyrank layout">
        <div class="head">授课机构排名</div>
        {% for org in orgs_hot %}
            <dl class="des">
                <dt class="num fl">{{ forloop.counter }}</dt>
                <dd>
                    <a href="{% url 'orgs:orgHome' org.id %}"><h1>{{ org.name }}</h1></a>
                    <p>{{ org.address }}</p>
                </dd>
            </dl>
        {% endfor %}
    </div>

</div>
</section>
<script>
$(function(){
    $('#jsStayBtn').on('click',function(){
        var name = $("#name").val()
        var mobile = $("#mobile").val()
        var courseName = $("#courseName").val()
        //2-15位中文
        if(!/^[\u4E00-\u9FFF_a-zA-Z]{2,15}$/.test(name)){
            alert("用户名由2-15位汉字或英文组成!")
            return
        }
        //11位数字
        if(!/^1[3|4|5|7|8]\d{9}$/.test(mobile)){
            alert("手机号码输入有误!")
            return
        }
        //2-20位中文\英文\数字
        if(!/^[\u2E80-\u9FFF_a-zA-Z0-9]{2,20}$/.test(courseName)){
            alert("课程名称输入有误!")
            return
        }
        $.ajax({
            cache: false,
            async: true,
            type: "POST",
            url: "{% url 'operations:userAsk' %}",
            data: $('#jsStayForm').serialize(),
            success: function(data){
                console.info(data)
                if(data.status == 'success'){
                    $('#jsStayForm')[0].reset();
                    $('#jsCompanyTips').text("")
                    alert("提交成功")
                }else if(data.status == 'fail'){
                    $('#jsCompanyTips').text(data.msg)
                }
            },
            error: function(a,b,c) {
                alert("系统繁忙,稍后重试")
            }
        })
    })
})
</script>
{% endblock %}
